package com.hqyj.springboot.modules.account.controller;

import com.github.pagehelper.PageInfo;
import com.hqyj.springboot.modules.account.entity.Resource;
import com.hqyj.springboot.modules.account.service.ResourceService;
import com.hqyj.springboot.modules.common.vo.Result;
import com.hqyj.springboot.modules.common.vo.Search;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    @PostMapping(value = "/resource",consumes = "application/json")
    public Result<Resource> addResource(@RequestBody Resource resource){
        return resourceService.addResource(resource);
    }

    @PutMapping(value = "/resource",consumes = "application/json")
    public Result<Resource> updateResource(@RequestBody Resource resource){
        return resourceService.updateResource(resource);
    }

    @DeleteMapping("/resource/{id}")
    public Result<Object> deleteResourceById(@PathVariable int id){
        return resourceService.deleteResourceById(id);
    }

    @GetMapping("/resource/{id}")
    public Resource getResourceById(@PathVariable int id) {
        return resourceService.getResourceById(id);
    }


    @PostMapping(value = "/resourceList", consumes = "application/json")
    public PageInfo<Resource> getResourcesBySearchBean(@RequestBody Search search) {
        return resourceService.getResourcesBySearch(search);
    }





}
